﻿using cubeAdjustment;
using System.Linq;
using System.Text;

namespace cubeAdjustment
{
    internal class Report
    {
        StringBuilder report;
        public string GetReport
        {
            get
            {
                return report.ToString();
            }
        }
        /// <summary>
        /// 构建高程网平差报告
        /// </summary>
        /// <param name="elevationFeature"></param>
        public Report(ElevationFeature elevationFeature)
        {
            report = new StringBuilder();
            report.AppendLine("B矩阵:");
            for (var i = 0; i < elevationFeature.B.RowCount; i++)
            {
                for (var j = 0; j < elevationFeature.B.ColumnCount; j++)
                {
                    report.Append(elevationFeature.B[i, j].ToString()+" ");
                }
                report.Append("\n");
            } 
            report.AppendLine("l矩阵:");
            foreach (var i in elevationFeature.l)
            {
                report.AppendLine(i.ToString());
            }
            report.AppendLine("最终权阵:");
            for (var i = 0; i < elevationFeature.P.RowCount; i++)
            {
                for (var j = 0; j < elevationFeature.P.ColumnCount; j++)
                {
                    report.Append(elevationFeature.P[i, j].ToString() + " ");
                }
                report.Append("\n");
            }
            report.AppendLine("法方程系数阵:");
            for (var i = 0; i < elevationFeature.Qxx.RowCount; i++)
            {
                for (var j = 0; j < elevationFeature.Qxx.ColumnCount; j++)
                {
                    report.Append(elevationFeature.Qxx[i, j].ToString() + " ");
                }
                report.Append("\n");
            }
            report.AppendLine("未知点高程改正数:");
            foreach (var i in elevationFeature.X)
            {
                report.AppendLine(i.ToString());
            }
            report.AppendLine("观测值改正数:");
            foreach (var i in elevationFeature.V)
            {
                report.AppendLine(i.ToString());
            }
            report.AppendLine("近似高程:");
            foreach (var i in elevationFeature.InitialElevation)
            {
                report.AppendLine(i.ToString());
            }
            report.AppendLine("高程平差值:");
            foreach (var i in elevationFeature.H0)
            {
                report.AppendLine(i.ToString());
            }

            report.Append("单位权中误差估值:");
            report.Append(elevationFeature.Sigma0.ToString() + "\n");

            /**//*resultBox.Text += "高差观测值的协因数阵：" + Q.ToString().Substring(Q.ToString().IndexOf('\n'));
*//*            resultBox.Text += "各观测值平差值的中误差估值：" + deh.ToString().Substring(deh.ToString().IndexOf('\n'));
*/
        }
        /// <summary>
        /// 构建平面网平差报告
        /// </summary>
        /// <param name="planeFeature"></param>
        public Report(PlaneFeature planeFeature)
        {
            report = new StringBuilder();
            ///
            ///TODO:将报告生成代码改成使用平面平差要素的类的代码
            ///
            report = new StringBuilder();
            report.AppendLine("近似坐标值:");
            report.AppendLine(string.Format("{0,14}", "点名") + string.Format("{0,14}", "X坐标") + string.Format("{0,14}", "Y坐标"));
/*            foreach (iPoint pointData in knownData.pointDatas)
            { report.AppendLine(string.Format("{0,16}", pointData.id) + string.Format("{0,16}", pointData.x) + string.Format("{0,16}", pointData.y)); }
            foreach (iPoint pointData in approximateCoordinate.points)
            { report.Text += string.Format("{0,16}", pointData.id) + string.Format("{0,16}", pointData.x.ToString("0.000")) + string.Format("{0,16}", pointData.y.ToString("0.000")) + "\n"; }

            report.AppendLine("\n  总点数：" + (knownData.pointDatas.Count + approximateCoordinate.points.Count));
            report.AppendLine("\n  已知点数：" + knownData.pointDatas.Count;
            report.AppendLine("\n  方向观测数：" + result.angleobs.Count;
            report.AppendLine("\n  边长观测数：" + result.distanceobs.Count;
            report.AppendLine("\n  多余观测数：" + (planeFeature.angleobs.Count + planeFeature.distanceobs.Count - 2 * approximateCoordinate.points.Count);*/
            report.AppendLine("\n  单位权中误差：" + planeFeature.sigma0.ToString("0.000\n"));
            report.AppendLine("\n  B矩阵:\n");
            for (var i = 0; i < planeFeature.B.RowCount; i++)
            {
                for (var j = 0; j < planeFeature.B.ColumnCount; j++)
                {
                    report.Append(planeFeature.B[i, j].ToString());
                }
                report.Append("\n");
            }
            report.AppendLine("\n  P矩阵:\n");
            for (var i = 0; i < planeFeature.P.RowCount; i++)
            {
                for (var j = 0; j < planeFeature.P.ColumnCount; j++)
                {
                    report.Append(planeFeature.P[i, j].ToString());
                }
                report.Append("\n");
            }
            report.AppendLine("\n  l矩阵（″/mm）:\n");
            foreach (var i in planeFeature.l)
            {
                report.AppendLine(i.ToString());
            }
            report.AppendLine("\n  N矩阵:\n");
            for (var i = 0; i < planeFeature.N.RowCount; i++)
            {
                for (var j = 0; j < planeFeature.N.ColumnCount; j++)
                {
                    report.Append(planeFeature.N[i, j].ToString());
                }
                report.Append("\n");
            }
            report.AppendLine("\n  V矩阵（″/mm）:\n");
            foreach (var i in planeFeature.V)
            {
                report.AppendLine(i.ToString());
            }
            report.AppendLine("\n  X矩阵(mm):\n");
            foreach (var i in planeFeature.X)
            {
                report.AppendLine(i.ToString());
            }
        }
    }
}
